/**
 * 区域表管理初始化
 */
var Region = {
    id: "RegionTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Region.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'regionId', visible: true, align: 'center', valign: 'middle'},
            {title: '区域编码', field: 'regionCode', visible: true, align: 'center', valign: 'middle'},
            {title: '区域名称', field: 'regionName', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'parentId', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'regionLevel', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'regionOrder', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'regionNameEn', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'regionShortnameEn', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Region.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Region.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加区域表
 */
Region.openAddRegion = function () {
    var index = layer.open({
        type: 2,
        shade:0.01,
        title: '添加区域表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/region/region_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看区域表详情
 */
Region.openRegionDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            shade:0.01,
            title: '区域表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/region/region_update/' + Region.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除区域表
 */
Region.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/region/delete", function (data) {
            Feng.success("删除成功!");
            Region.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("regionId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询区域表列表
 */
Region.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Region.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Region.initColumn();
    var table = new BSTable(Region.id, "/region/list", defaultColunms);
    table.setPaginationType("client");
    Region.table = table.init();
    layui.use('layer', function () {

    })
});
